package com.borqsprocessmanager.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.borqsprocessmanager.App;
import com.borqsprocessmanager.R;

public class ActionDialog extends Dialog {

    private static ActionDialog mInstance = null;

    private Context mContext;
    private Button unInstallBtn, optBtn;
    public static final int TYPE_ONLY_UNINSTILL = 0;
    public static final int TYPE_ONLY_KILLPROCESS = 1;
    public static final int TYPE_UNINSTILL_AND_KILLPROCESS = 2;
    public static final int TYPE_NOROOT_AUTOPROCESS = 3;

    private View killProcessLayout, excisionLayout, uninstallLayout;
    private TextView dataText;

    public static void showDialog(Context context,
            android.view.View.OnClickListener listener, int type) {
        if (mInstance == null) {
            mInstance = new ActionDialog(context);
        }
        mInstance.setDialogListener(listener);
        mInstance.setLayout(type);
        mInstance.show();
    }

    public static void dissmisDialog() {
        if (mInstance != null) {
            mInstance.dismiss();
        }
    }

    public ActionDialog(Context context, int theme) {
        super(context, theme);
        init(context);
    }

    protected ActionDialog(Context context, boolean cancelable,
            OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    public ActionDialog(Context context) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        init(context);

    }

    private void init(Context context) {
        mContext = context;
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_action);
        setTitle("Set the App");

        findView();
    }

    private void findView() {
        // unInstallBtn = (Button) findViewById(R.id.dialog_action_left);
        // optBtn = (Button) findViewById(R.id.dialog_acion_right);
        // killProcessLayout = findViewById(R.id.dialog_right_layout);
        // excisionLayout = findViewById(R.id.dialog_excision_layout);
        uninstallLayout = findViewById(R.id.dialog_left_layout);
        dataText = (TextView) uninstallLayout
                .findViewById(R.id.dialog_action_left_text);
    }

    private void setLayout(int type) {
        switch (type) {
        case TYPE_ONLY_UNINSTILL:
            killProcessLayout.setVisibility(View.GONE);
            excisionLayout.setVisibility(View.GONE);
            dataText.setText(App.mContext.getText(R.string.action_uninstall));
            break;
        case TYPE_UNINSTILL_AND_KILLPROCESS:
            killProcessLayout.setVisibility(View.VISIBLE);
            excisionLayout.setVisibility(View.VISIBLE);
            dataText.setText(App.mContext.getText(R.string.action_uninstall));
            break;

        case TYPE_NOROOT_AUTOPROCESS:
            killProcessLayout.setVisibility(View.GONE);
            excisionLayout.setVisibility(View.GONE);
            dataText.setText(App.mContext.getText(R.string.action_noroot));
            break;
        default:
            break;
        }
    }

    public void setDialogListener(android.view.View.OnClickListener listener) {
        excisionLayout.setOnClickListener(listener);
        killProcessLayout.setOnClickListener(listener);
        // unInstallBtn.setOnClickListener(listener);
        // optBtn.setOnClickListener(listener);
    }
}
